import { usePageResponseSuccess } from '~/utils/response';

export default eventHandler((event) => {
  const query = getQuery(event);
  const {
    page = 1,
    pageSize = 10,
    keyword = '',
    technicalType = '',
    status = '',
  } = query;

  const technicalResources = [
    {
      id: '1',
      name: '客户预约表单',
      code: 'FORM-001',
      technicalType: 'FORM_TEMPLATE',
      category: 'TECHNICAL',
      status: 'ACTIVE',
      description: '通用客户预约表单模板',
      version: '1.0.0',
      author: '系统管理员',
      createTime: '2024-01-01 00:00:00',
      updateTime: '2024-01-01 00:00:00',
    },
    {
      id: '2',
      name: '收入统计报表',
      code: 'REPORT-001',
      technicalType: 'REPORT_TEMPLATE',
      category: 'TECHNICAL',
      status: 'ACTIVE',
      description: '收入统计分析报表模板',
      version: '1.2.0',
      author: '财务部门',
      createTime: '2024-01-01 00:00:00',
      updateTime: '2024-01-01 00:00:00',
    },
    {
      id: '3',
      name: '审批流程节点',
      code: 'WORKFLOW-001',
      technicalType: 'WORKFLOW_NODE',
      category: 'TECHNICAL',
      status: 'ACTIVE',
      description: '通用审批流程节点模板',
      version: '1.1.0',
      author: '流程管理员',
      createTime: '2024-01-01 00:00:00',
      updateTime: '2024-01-01 00:00:00',
    },
    {
      id: '4',
      name: '用户认证接口',
      code: 'API-001',
      technicalType: 'API_TEMPLATE',
      category: 'TECHNICAL',
      status: 'ACTIVE',
      description: '用户登录认证API模板',
      version: '2.0.0',
      author: '开发团队',
      createTime: '2024-01-01 00:00:00',
      updateTime: '2024-01-01 00:00:00',
    },
    {
      id: '5',
      name: '资源查询接口',
      code: 'API-002',
      technicalType: 'API_TEMPLATE',
      category: 'TECHNICAL',
      status: 'ACTIVE',
      description: '资源信息查询API模板',
      version: '1.5.0',
      author: '开发团队',
      createTime: '2024-01-01 00:00:00',
      updateTime: '2024-01-01 00:00:00',
    },
  ];

  // 模拟搜索过滤
  let filteredResources = technicalResources;

  if (keyword) {
    filteredResources = filteredResources.filter(
      (resource) =>
        resource.name.includes(keyword as string) ||
        resource.code.includes(keyword as string),
    );
  }

  if (technicalType) {
    filteredResources = filteredResources.filter(
      (resource) => resource.technicalType === technicalType,
    );
  }

  if (status) {
    filteredResources = filteredResources.filter(
      (resource) => resource.status === status,
    );
  }

  return usePageResponseSuccess(page, pageSize, filteredResources);
});
